<%--
  Created by IntelliJ IDEA.
  User: 王文尧
  Date: 2024/7/12
  Time: 7:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
  <title>Title</title>
</head>
<body>
<div style="width: 1000px;margin: auto">
  学号: <input type="text" id="sno" value="${param.sNo}"/>
  姓名: <input type="text" id="sname" value="${param.sName}"/>
  性别: <select id="sex">
    <option value="" ${param.sex=="" ? "selected" : ""}>不限</option>
    <option ${param.sex == "男" ? "selected" : ""}>男</option>
    <option ${param.sex == "女" ? "selected" : ""}>女</option>
  </select>
  年龄: <input id="age" value="${param.age}"/>
  <button onclick="query(1)">查询</button>
</div>
<table border="1" align="center" width="1000px">
  <tr>
    <th>学号</th>
    <th>姓名</th>
    <th>密码</th>
    <th>性别</th>
    <th>年龄</th>
  </tr>
  <c:forEach items="${pageInfo.data}" var="stu">
    <tr>
      <td>${stu.SNo}</td>
      <td>${stu.SName}</td>
      <td>${stu.password}</td>
      <td>${stu.sex}</td>
      <td>${stu.age}</td>
    </tr>
  </c:forEach>
</table>
<div style="width: 1000px;margin: auto">
  当前页${pageInfo.pageIndex}<br/>
  一页几条${pageInfo.pageSize}<br/>
  一共几页${pageInfo.totalPageNum}<br/>
  一共几条${pageInfo.totalDataNum}<br/>
  <a href="javascript:query(1)">首页</a>
  <c:choose>
    <c:when test="${pageInfo.pageIndex > 1}">
      <a href="javascript:query(${pageInfo.pageIndex-1})">上一页</a>
    </c:when>
    <c:otherwise>
      上一页
    </c:otherwise>
  </c:choose>
  <c:forEach var="i" begin="1" end="${pageInfo.totalPageNum}">
    <c:choose>
      <c:when test="${i!=pageInfo.pageIndex}">
        <a href="javascript:query(${i})">${i}</a>
      </c:when>
      <c:otherwise>
        ${i}
      </c:otherwise>
    </c:choose>
  </c:forEach>
  <c:choose>
    <c:when test="${pageInfo.pageIndex < pageInfo.totalPageNum}">
      <a href="javascript:query(${pageInfo.pageIndex+1})">下一页</a>
    </c:when>
    <c:otherwise>
      下一页
    </c:otherwise>
  </c:choose>
  <a href="javascript:query(${pageInfo.totalPageNum})">尾页</a>

  跳转到<input type="number" value="${pageInfo.pageIndex}" id="jumpIndex"/>页<button onclick="jumpPageTo()">跳转</button>
  一页<select onchange="changePageSize(this)">
  <option ${pageInfo.pageSize == 5 ? "selected" : ""}>5</option>
  <option ${pageInfo.pageSize == 10 ? "selected" : ""}>10</option>
  <option ${pageInfo.pageSize == 20 ? "selected" : ""}>20</option>
</select>条
  总条数 ${pageInfo.totalDataNum}
</div>
<script type="text/javascript">
  function jumpPageTo() {
    var jumpIndex = document.getElementById("jumpIndex").value; // todo:后面再做校验
    query(jumpIndex);
    //location.href="manage?op=queryAllStudentsByPage&pageIndex=" + jumpIndex + "&pageSize=${pageInfo.pageSize}";
  }
  function changePageSize(obj){
    //location.href="manage?op=queryAllStudentsByPage&pageIndex=1&pageSize=" + obj.value;
    var sNo = document.getElementById("sno").value;
    var sName = document.getElementById("sname").value;
    var sex = document.getElementById("sex").value;
    var age = document.getElementById("age").value;

    location.href="manage?op=queryAllStudentsByPage2&pageIndex=1&pageSize=" + obj.value + "&sNo=" + sNo + "&sName=" + sName + "&sex=" + sex + "&age=" + age;
  }
  function query(index){
    // debugger
    var sNo = document.getElementById("sno").value;
    var sName = document.getElementById("sname").value;
    var sex = document.getElementById("sex").value;
    var age = document.getElementById("age").value;

    location.href="manage?op=queryAllStudentsByPage2&pageIndex=" + index + "&pageSize=${pageInfo.pageSize}&sNo=" + sNo + "&sName=" + sName + "&sex=" + sex + "&age=" + age;
  }
</script>
</body>
</html>
